package cn.itcast.bos.service.base.Impl;

import cn.itcast.bos.Dao.base.StandardDao;
import cn.itcast.bos.domain.base.Standard;
import cn.itcast.bos.service.base.StandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2017/7/19.
 */
@Service
@Transactional
public class StandardServiceImpl implements StandardService {

    //注入Dao
    @Autowired
    private StandardDao standardDao;
    @Override
    //调用此方法是,清除掉缓存
    @CacheEvict(value = "standard",allEntries = true)
    public void save(Standard standard) {
        standardDao.save(standard);
    }

    @Override
    //针对数据在不同条件下进行缓存,设置cacheable的key
    @Cacheable(value = "standard",key = "#pageable.pageNumber+'_'+#pageable.pageSize")
    public Page<Standard> pageQuery(Pageable pageable) {
        Page<Standard> pageData = standardDao.findAll(pageable);
        return pageData;
    }

    @Override
    //将此方法加入注解
    @Cacheable("standard")
    public List<Standard> findAll() {
        List<Standard> standards = standardDao.findAll();
        return standards;
    }
}
